package com.etone.smartAudit.service;

public class CPUTestThread implements Runnable {
    private boolean stopCpu = false;

    @Override
    public void run() {
        int busyTime = 20;
        int idleTime = busyTime;
        long startTime = 0;
        while (true) {
            startTime = System.currentTimeMillis();
            System.out.println(System.currentTimeMillis()+","+startTime+","+(System.currentTimeMillis() - startTime));

            // busy loop
            while ((System.currentTimeMillis() - startTime) <= busyTime)
                ;
            // idle loop
            try {
                Thread.sleep(idleTime);
            } catch (InterruptedException e) {
                System.out.println(e);
            }
        }
    }

    public void setStopCpu(boolean stopCpu) {
        this.stopCpu = stopCpu;
    }
}
